This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter. # Cellchat
source("./tianfengRwrappers.R")
library(CellChat)
#推断细胞间通信网络,不要使用并行计算!
cor <- computeCommunProb(cor)
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|=== | 3%
|
|==== | 4%
|
|===== | 5%
|
|====== | 6%
|
|======= | 7%
|
|======== | 8%
|
|========= | 9%
|
|========== | 10%
|
|=========== | 11%
|
|============ | 12%
|
|============= | 13%
|
|============== | 14%
|
|=============== | 15%
|
|================ | 16%
|
|================= | 17%
|
|================== | 18%
|
|=================== | 19%
|
|==================== | 20%
|
|===================== | 21%
|
|====================== | 22%
|
|======================= | 23%
|
|======================== | 24%
|
|========================= | 25%
|
|========================== | 26%
|
|=========================== | 27%
|
|============================ | 28%
|
|============================= | 29%
|
|============================== | 30%
|
|=============================== | 31%
|
|================================ | 32%
|
|================================= | 33%
|
|================================== | 34%
|
|=================================== | 35%
|
|==================================== | 36%
|
|===================================== | 37%
|
|====================================== | 38%
|
|======================================= | 39%
|
|======================================== | 40%
|
|========================================= | 41%
|
|========================================== | 42%
|
|=========================================== | 43%
|
|============================================ | 44%
|
|============================================= | 45%
|
|============================================== | 46%
|
|=============================================== | 47%
|
|================================================ | 48%
|
|================================================= | 49%
|
|================================================== | 50%
|
|=================================================== | 51%
|
|==================================================== | 52%
|
|===================================================== | 53%
|
|====================================================== | 54%
|
|======================================================= | 55%
|
|======================================================== | 56%
|
|========================================================= | 57%
|
|========================================================== | 58%
|
|=========================================================== | 59%
|
|============================================================ | 60%
|
|============================================================= | 61%
|
|============================================================== | 62%
|
|=============================================================== | 63%
|
|================================================================ | 64%
|
|================================================================= | 65%
|
|================================================================== | 66%
|
|=================================================================== | 67%
|
|==================================================================== | 68%
|
|===================================================================== | 69%
|
|====================================================================== | 70%
|
|======================================================================= | 71%
|
|======================================================================== | 72%
|
|========================================================================= | 73%
|
|========================================================================== | 74%
|
|=========================================================================== | 75%
|
|============================================================================ | 76%
|
|============================================================================= | 77%
|
|============================================================================== | 78%
|
|=============================================================================== | 79%
|
|================================================================================ | 80%
|
|================================================================================= | 81%
|
|================================================================================== | 82%
|
|=================================================================================== | 83%
|
|==================================================================================== | 84%
|
|===================================================================================== | 85%
|
|====================================================================================== | 86%
|
|======================================================================================= | 87%
|
|======================================================================================== | 88%
|
|========================================================================================= | 89%
|
|========================================================================================== | 90%
|
|=========================================================================================== | 91%
|
|============================================================================================ | 92%
|
|============================================================================================= | 93%
|
|============================================================================================== | 94%
|
|=============================================================================================== | 95%
|
|================================================================================================ | 96%
|
|================================================================================================= | 97%
|
|================================================================================================== | 98%
|
|=================================================================================================== | 99%
|
|====================================================================================================| 100%
#推断细胞间通信网络,不要使用并行计算!
cor <- computeCommunProb(cor)
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|=== | 3%
|
|==== | 4%
|
|===== | 5%
|
|====== | 6%
|
|======= | 7%
|
|======== | 8%
|
|========= | 9%
|
|========== | 10%
|
|=========== | 11%
|
|============ | 12%
|
|============= | 13%
|
|============== | 14%
|
|=============== | 15%
|
|================ | 16%
|
|================= | 17%
|
|================== | 18%
|
|=================== | 19%
|
|==================== | 20%
|
|===================== | 21%
|
|====================== | 22%
|
|======================= | 23%
|
|======================== | 24%
|
|========================= | 25%
|
|========================== | 26%
|
|=========================== | 27%
|
|============================ | 28%
|
|============================= | 29%
|
|============================== | 30%
|
|=============================== | 31%
|
|================================ | 32%
|
|================================= | 33%
|
|================================== | 34%
|
|=================================== | 35%
|
|==================================== | 36%
|
|===================================== | 37%
|
|====================================== | 38%
|
|======================================= | 39%
|
|======================================== | 40%
|
|========================================= | 41%
|
|========================================== | 42%
|
|=========================================== | 43%
|
|============================================ | 44%
|
|============================================= | 45%
|
|============================================== | 46%
|
|=============================================== | 47%
|
|================================================ | 48%
|
|================================================= | 49%
|
|================================================== | 50%
|
|=================================================== | 51%
|
|==================================================== | 52%
|
|===================================================== | 53%
|
|====================================================== | 54%
|
|======================================================= | 55%
|
|======================================================== | 56%
|
|========================================================= | 57%
|
|========================================================== | 58%
|
|=========================================================== | 59%
|
|============================================================ | 60%
|
|============================================================= | 61%
|
|============================================================== | 62%
|
|=============================================================== | 63%
|
|================================================================ | 64%
|
|================================================================= | 65%
|
|================================================================== | 66%
|
|=================================================================== | 67%
|
|==================================================================== | 68%
|
|===================================================================== | 69%
|
|====================================================================== | 70%
|
|======================================================================= | 71%
|
|======================================================================== | 72%
|
|========================================================================= | 73%
|
|========================================================================== | 74%
|
|=========================================================================== | 75%
|
|============================================================================ | 76%
|
|============================================================================= | 77%
|
|============================================================================== | 78%
|
|=============================================================================== | 79%
|
|================================================================================ | 80%
|
|================================================================================= | 81%
|
|================================================================================== | 82%
|
|=================================================================================== | 83%
|
|==================================================================================== | 84%
|
|===================================================================================== | 85%
|
|====================================================================================== | 86%
|
|======================================================================================= | 87%
|
|======================================================================================== | 88%
|
|========================================================================================= | 89%
|
|========================================================================================== | 90%
|
|=========================================================================================== | 91%
|
|============================================================================================ | 92%
|
|============================================================================================= | 93%
|
|============================================================================================== | 94%
|
|=============================================================================================== | 95%
|
|================================================================================================ | 96%
|
|================================================================================================= | 97%
|
|================================================================================================== | 98%
|
|=================================================================================================== | 99%
|
|====================================================================================================| 100%
#若细胞群中只有少数细胞出现联系(<10个),则过滤掉它们
cor <- filterCommunication(cor,min.cells = 10)
#提取表达网络矩阵
df.net <- subsetCommunication(cor)
#推断信号通路
cor <- computeCommunProbPathway(cor)
#合并通信网络数据
cor <- aggregateNet(cor)
write.csv(df.net,"./datatable/cellchat_res.csv", row.names = F)
cor <- readRDS("CA2_cellchat.rds")
# cor@idents <- plyr::revalue(cor@idents, c("Mod_SMC"="Fibroblast", "SMC_0"="SMC1","SMC_1"="Fibromyocyte",
# "SMC_2"="Pericyte","SMC_3"="SMC2"))
table(cor@idents)
SMC1 Fibromyocyte Pericyte SMC2 EC FB
3430 2294 1590 1021 6092 1224
Macrophage T cell NK cell Neural progenitor B cell Mast cell
9832 12245 4125 366 2206 430
groupSize <- as.numeric(table(cor@idents))
netVisual_circle(cor@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
netVisual_heatmap(cor, measure = "weight", signaling = NULL, color.heatmap = c("#f1f1f1", "#ff2121"))
Do heatmap based on a single object
#一次分析不同细胞亚群
mat <- cor@net$weight
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
# pheatmap(mat, display_numbers = FALSE, number_color ="black", cluster_rows = FALSE,
# cluster_cols = FALSE, color = colorRampPalette(c("#1E90FF", "white", "#ff2121"))(400), border_color = NA)
table(cor@idents)
SMC1 Fibromyocyte Pericyte SMC2 EC FB
3430 2294 1590 1021 6092 1224
Macrophage T cell NK cell Neural progenitor B cell Mast cell
9832 12245 4125 366 2206 430
netVisual_chord_gene(cor, sources.use = c(4), targets.use = c(1:12), lab.cex = 0.5, legend.pos.y = 30)
netVisual_chord_gene(cor, sources.use = c(1:12), targets.use = c(4), lab.cex = 0.5, legend.pos.y = 30)
#指定pathway
pathways.show <- c("TGFb") #SMC2
# Hierarchy plot
vertex.receiver = c(2,3,6,7,13) # a numeric vector.
netVisual_aggregate(cor, signaling = pathways.show, layout = "hierarchy", vertex.receiver = vertex.receiver)
netVisual_aggregate(cor, signaling = pathways.show, layout = "circle")
# netVisual_aggregate(cor, signaling = pathways.show, layout = "chord")
# Heatmap
netVisual_heatmap(cor, signaling = pathways.show, color.heatmap = c("#f1f1f1", "#ff2121"))
#可视化单个配体受体对的影响
netAnalysis_contribution(cor, signaling = pathways.show)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.